package com.smedi.ismedi.authoritymanagement.core.port.adapter.persistence.repository.impl;

import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.smedi.ismedi.authoritymanagement.core.domain.aggregatemodel.TermRouter;
import com.smedi.ismedi.authoritymanagement.core.domain.repository.TermRepository;
import com.smedi.ismedi.authoritymanagement.core.port.adapter.persistence.model.TermRouterEntity;
import com.smedi.ismedi.authoritymanagement.core.port.adapter.persistence.mybatis.mapper.TermRouterMapper;
import com.smedi.ismedi.web.starter.util.DozerUtil;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

@Slf4j
@Repository("TermRouter")
@AllArgsConstructor
public class TermRouterRepositoryImpl extends ServiceImpl<TermRouterMapper, TermRouterEntity> implements TermRepository, IService<TermRouterEntity> {
    private final DozerUtil dozerUtil;

    @Override
    public <T> T selectByTermId(Long termId) {
        TermRouterEntity row = this.getBaseMapper().selectById(termId);
        return (T) dozerUtil.convertor(row, TermRouter.class);
    }

    @Override
    public <T> T doInsert(T data) {
        TermRouterEntity row = dozerUtil.convertor(data, TermRouterEntity.class);
        this.getBaseMapper().insert(row);
        return (T) dozerUtil.convertor(row, TermRouter.class);
    }

    @Override
    public <T> T doUpdate(T data) {
        TermRouterEntity row = dozerUtil.convertor(data, TermRouterEntity.class);
        this.getBaseMapper().updateById(row);
        return (T) dozerUtil.convertor(row, TermRouter.class);
    }
}
